﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.IO;
using System.Xml.Linq;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using EnvDTE80;
using Microsoft.VisualStudio.CommandBars;

using dotNails.Util;
using dotNails.UI;
using System.Windows.Forms.Integration;
using dotNails.CodeGen.Models;
using EnvDTE;

namespace dotNails.UI {
	[Obsolete("This class is obsolete and should not be used.  Use straight WPF instead - see MainWindow.xaml for an example.")]
	public partial class Manager : Form, IUserControlParent {
		#region Properties
		protected ConfigData _configData;
		protected ElementHost _host;
		public DTE2 DTE { get; set; }
		public EnvDTE.AddIn AddInInstance { get; set; }
		public MenuManager MenuManager { get; set; }
		public CommandBarPopup PopupMenu { get; set; }
		#endregion Properties

		public Manager(DTE2 dte, EnvDTE.AddIn addInInstance, MenuManager menuManager, CommandBarPopup popupMenu) {
			InitializeComponent();

			DTE = dte;
			AddInInstance = addInInstance;
			MenuManager = menuManager;
			PopupMenu = popupMenu;

			_configData = LoadConfigData();
		}

		protected ConfigData LoadConfigData() {
			ConfigData configData;
			
			string configFilePath = ConfigData.GetConfigFilePath(DTE.Solution.FileName);
			configData = new ConfigData(configFilePath);

			return configData;
		}

		public void SetConfigData(ConfigData configData) {
			_configData = configData;
		}

		protected override void OnLoad(EventArgs e) {
			base.OnLoad(e);

			// Find all dbmls in the solution
			List<DbmlData> dbmls = AddInUtil.GetAllDBMLsInSolution(DTE);

			// Create the ElementHost control for hosting the
			// WPF UserControl.
			_host = new ElementHost();
			_host.Dock = DockStyle.Fill;

			// Create the WPF UserControl.
			//DatabaseList uc = new DatabaseList(this, dbmls);

			// Assign the WPF UserControl to the ElementHost control's
			// Child property.
			//_host.Child = uc;

			// Add the ElementHost control to the form's
			// collection of child controls.
			//this.Controls.Add(_host);

		}

		public void LoadUserControl(System.Windows.Controls.UserControl userControl) {
			_host.Child = userControl;
		}

		public void RunCustomToolOnFile(string filePath) {
			ProjectItem dbmlProjectItem = AddInUtil.GetProjectItemByFilePath(DTE, filePath);

			AddInUtil.SetCustomToolOnProjectItem(dbmlProjectItem);
			AddInUtil.RunCustomToolOnProjectItem(dbmlProjectItem);
		}


	}
}
